package com.fmistuff.chain.nodes;

import java.util.HashMap;

public class NumNode extends MarkovNode {

	private static HashMap<String, MarkovNode> pool;

	static {
		pool = new HashMap<String, MarkovNode>();
		pool.put("0", new NumNode("1", 0.05f));
		pool.put("1", new NumNode("1", 0.05f));
		pool.put("2", new NumNode("2", 0.05f));
		pool.put("3", new NumNode("3", 0.05f));
		pool.put("4", new NumNode("4", 0.05f));
		pool.put("5", new NumNode("5", 0.05f));
		pool.put("6", new NumNode("6", 0.06f));
		pool.put("7", new NumNode("7", 0.09f));
		pool.put("8", new NumNode("8", 0.08f));
		pool.put("9", new NumNode("9", 0.05f));
	}
	

	public NumNode() {
		this(pickANode(pool).getData());
	}

	public NumNode(String data) {
		this(data, 0.5f);
	}
	
	protected NumNode(String data, float probability){
		super(data, probability);
	}


	@Override
	public String descend() {
		MarkovNode currentNode = super.pickANode(pool);
		if (!isFinal()) {
			return getData() + currentNode.descend();
		}

		return getData();
	}
	
	@Override
	public boolean isFinal() {
		return RANDOM.nextInt(32) < 4; //around 1/4-th chance
	}

	

}
